package com.mybase.app.fourBase;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.mybase.app.R;

/**
 * Created by happy_000 on 2014/12/1.
 */
public class SecondActivity extends ActionBarActivity {
    private EditText editText;
    private MenuItem actionfinsh;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        LinearLayout line=new LinearLayout(this);
        TextView textView=new TextView(this);
        editText=new EditText(this);
        editText.setHint("请输入返回值");
        line.addView(textView);
        line.addView(editText);
        //    得到跳转到该Activity的Intent对象
        Intent intent = getIntent();
        String str = intent.getStringExtra("key");
        Bundle bundle = intent.getBundleExtra("bundle");
        String world = bundle.getString("hello");
        textView.setText("上个activity传入内容:"+str+"&&"+world);
        setContentView(line);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.fs_menu, menu);
        actionfinsh = menu.findItem(R.id.second_finsh);
        return super.onCreateOptionsMenu(menu);
    }

    @Override
    public boolean onPrepareOptionsMenu(Menu menu) {
        return super.onPrepareOptionsMenu(menu);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case R.id.second_finsh:
                //创建intent对象，
                String string = editText.getText().toString();
                Intent intent = new Intent();
                intent.putExtra("remark", string);
                //设置返回值，将intent对象作为数据返回到源Activity
                setResult(RESULT_OK, intent);
                finish();
                break;
        }
        return super.onOptionsItemSelected(item);
    }
}
